<template>
  <van-popup
    v-model:show="showBatchTypePopup"
    position="center"
    round
    :style="{ height: '460px', overflow: 'hidden' }"
    closeable
    @close="beforeClose"
  >
    <div class="popup-container">
      <div class="title">请选择填报批次</div>
      <div class="popup-schoolLevel">
        <div
          :class="[
            'schoolLevel-item',
            currentBatchType == item.batchType ? 'active' : '',
          ]"
          v-for="(item, index) in batchTypeList"
          :key="index"
          @click="changeCurrentSchoolLevel(item)"
        >
          <div class="first-line">{{ item.batchTypeName }}</div>
          <div class="second-line">
            <div>{{ item.recordYear }}年省控分数线 {{ item.lineScore }}</div>
          </div>
        </div>
      </div>
      <div class="bottom-btn">
        <div class="right-btn" @click="confirmSchoolLevel">确 定</div>
      </div>
    </div>
  </van-popup>
</template>

<script setup>
import { ref, reactive, onMounted, computed } from 'vue';
import { useVolunteerStore } from '@/store/volunteer';

const emit = defineEmits(['onConfirmBatchType', 'onCloseBatchType']);

const showBatchTypePopup = ref(true);

const store = useVolunteerStore();

const currentBatchType = ref(store.volunteerInfo.batchType);

const batchTypeList = computed(() => store.batchTypeList);

const changeCurrentSchoolLevel = (item) => {
  console.log(
    '---------changeCurrentSchoolLevel-----------_>',
    item,
    batchTypeList.value
  );
  currentBatchType.value = item.batchType;
};

const confirmSchoolLevel = () => {
  console.log(
    '---------------confirmSchoolLevel-----2------->currentBatchType',
    currentBatchType.value
  );
  store.setDefaultBatchType(currentBatchType.value);
  const temp = batchTypeList.value.find(
    (item) => item.batchType == currentBatchType.value
  );
  emit('onConfirmBatchType', temp);
};

const beforeClose = () => {
  emit('onCloseBatchType');
};

onMounted(() => {});
</script>

<style scoped lang="scss">
.popup-container {
  width: 560px;
}
.title {
  padding: 32px 0 24px 32px;
  display: flex;
  align-items: flex-end;
  font-family: PingFang-SC, PingFang-SC;
  font-weight: bold;
  font-size: 28px;
  color: #222222;
  line-height: 22px;
  text-align: left;
  font-style: normal;
  span {
    font-size: 22px;
    color: #999999;
  }
}
.popup-schoolLevel {
  padding: 32px 32px 150px 32px;
  height: 280px;
  overflow-y: auto;
  .schoolLevel-item {
    width: 100%;
    margin-bottom: 24px;
    padding: 24px;
    box-sizing: border-box;
    border: 2px solid #b8adad;
    border-radius: 8px;
    .first-line {
      display: flex;
      font-size: 26px;
    }
    .second-line {
      display: flex;
      flex-direction: row;
      align-items: center;
      display: flex;
      flex-direction: row;
      align-items: center;
      font-size: 22px;
    }
    &.active {
      color: $primary-color;
      background: #ffffff;
      border-radius: 8px;
      border: 2px solid $primary-color;
    }
  }
}
.bottom-btn {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 24px;
  background: #ffffff;
  box-shadow: 0px -2px 4px 0px rgba(188, 188, 188, 0.5);
  box-sizing: border-box;
  display: flex;
  flex-direction: row;
  justify-content: center;
  gap: 24px;
  z-index: 2;

  .left-btn,
  .right-btn {
    flex-shrink: 0;
    width: 98%;
    height: 62px;
    background: #f8f8f8;
    border-radius: 6px;
    font-family: PingFang-SC, PingFang-SC;
    font-weight: bold;
    font-size: 24px;
    color: #999999;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
  }

  .left-btn {
    background: #f8f8f8;
    border: 1px solid #f8f8f8;
    &.active {
      border: 1px solid $primary-color;
      color: $primary-color;
    }
  }
  .right-btn {
    color: #ffffff;
    background: $primary-color;
  }
}
</style>
